import Vue from 'vue'
import Vuex from 'vuex'
import { getInfo, formDataShow, getQdqx } from '@/api'
import declare from './modules/declare'
import newDeclare from './modules/newDeclare'
Vue.use(Vuex)

const store = new Vuex.Store({
  modules: {
    declare,
    newDeclare,
  },
  //状态
  state: {
    loadding: false,
    userInfo: {}, // 用户信息
    columns: [
      // 单位推荐、形式审查、专家评审
      {
        title: '序号',
        dataIndex: 'key',
        width: 80,
      },
      {
        title: '申报单位',
        dataIndex: 'deptName',
        width: 150,
      },
      {
        title: '作品名称',
        width: 150,
        key: 'name',
        slots: { title: 'baseName' },
        scopedSlots: { customRender: 'name' },

      },
      {
        title: '主要完成人',
        dataIndex: 'doneUsers',
        width: 150,
      },
      {
        title: '奖项等级',
        dataIndex: 'grade',
        width: 150,
        scopedSlots: { customRender: 'grade' },
        filters: [
          {
            text: 'Joe',
            value: 'Joe',
          },
          {
            text: 'Jim',
            value: 'Jim',
          }
        ],
        filterMultiple: false,
      },
      // {
      //   title: '申请时间',
      //   dataIndex: 'createTime',
      //   width: 150,
      // },
      {
        title: '审核状态',
        dataIndex: 'stateName',
        width: 150,
      },
      {
        title: '操作',
        key: 'action',
        scopedSlots: { customRender: 'action' },
        width: 190,
        fixed: 'right'
      },
    ],
    columns2: [
      // 单位推荐、形式审查、专家评审
      {
        title: '序号',
        dataIndex: 'key',
        width: 80,
      },
      {
        title: '申报单位',
        dataIndex: 'deptName',
        width: 150,
      },
      {
        title: '作品名称',
        width: 150,
        key: 'name',
        slots: { title: 'baseName' },
        scopedSlots: { customRender: 'name' },

      },
      {
        title: '主要完成人',
        dataIndex: 'doneUsers',
        width: 150,
      },
      {
        title: '奖项等级',
        dataIndex: 'grade',
        width: 150,
        scopedSlots: { customRender: 'grade' },
        filters: [
          {
            text: 'Joe',
            value: 'Joe',
          },
          {
            text: 'Jim',
            value: 'Jim',
          }
        ],
        filterMultiple: false,
      },
      // {
      //   title: '申请时间',
      //   dataIndex: 'createTime',
      //   width: 150,
      // },
      {
        title: '审核状态',
        dataIndex: 'stateName',
        width: 150,
      },
      {
        title: '操作',
        key: 'action',
        scopedSlots: { customRender: 'action' },
        width: 190,
        fixed: 'right'
      },
    ],
    formData: [],
    userQX: [
      {
        hidden: false,
        name: '首页',
        path: '/index',
      },
      {
        hidden: false,
        name: '公告',
        path: '/declare',
      },
    ], // 用户权限
    iptDis: false, // 申报详情表单是否禁止输入
  },
  //状态修改方法
  // 使用store.commit()来调用
  mutations: {
    showloadding(state, load) {
      state.loadding = load
    },
    SET_USER_INFO(state, option) {
      state.userInfo = option || {}
    },
    SET_FROM_DATA(state, option) {
      state.formData = option || []
    },
    SET_USER_QX(state, option) {
      state.userQX = option
    },
    SET_IPT_DIS(state, option) {
      state.iptDis = option
    },
  },
  // 可以用store.dispatch来调用
  actions: {
    setloadding(context, load) {
      context.commit('showloadding', load)
    },
    // 获取用户信息
    GET_USER_INFO(context) {
      getInfo().then((res) => {
        if (res.code != 200) return this.$message.err(res.msg)
        context.commit('SET_USER_INFO', res.user)
        sessionStorage.setItem('userInfo', JSON.stringify(res.user))
      })
    },
    // 获取用户权限
    GET_USER_QX(context) {
      getQdqx().then((res) => {
        if (res.code != 200) return this.$message.err(res.msg)
        context.commit('SET_USER_QX', res.data)
        sessionStorage.setItem('userQx', JSON.stringify(res.data))
      })
    },
    GET_USER_DATA(context, taskId) {
      formDataShow(taskId).then((res) => {
        console.log(res,'ftomdata')
        let datas = res.data
        let formData = []
        datas.forEach((i) => {
          let strings = i.split('--__!!')
          let controlValue = null
          let controlDefault = null
          switch (strings[1]) {
            case 'radio':
              controlValue = 0
              controlDefault = strings[4]
              break
            // default:
          }
          formData.push({
            controlId: strings[0],
            controlType: strings[1],
            controlLable: strings[2],
            controlIsParam: strings[3],
            controlValue: controlValue,
            controlDefault: controlDefault,
          })
        })
        context.commit('SET_FROM_DATA', formData)
      })
    },
  },
})
// 导出
export default store
